package com.zdy.im.user.controller;



import java.util.ArrayList;
import java.util.List;

import com.sixeco.framework.core.db.IterableConverter;
import com.zdy.im.user.UrlCommand;
import com.zdy.im.user.dto.request.ImJoinFriendStatusRequestDto;
import com.zdy.im.user.vo.request.ImRefuseJoinFriendRequestVo;
import com.zdy.im.user.dto.response.ImJoinFriendResponseDto;
import com.zdy.im.user.facade.ImJoinFriendFacade;
import com.zdy.im.user.service.ImJoinFriendService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.beans.factory.annotation.Autowired;

import com.sixeco.framework.http.data.vo.ResponseResultList;
import com.sixeco.framework.http.handler.OutputResponse;
import com.sixeco.framework.http.data.vo.HttpRequestByIdVo;
import com.sixeco.framework.common.data.BasePage;
import com.sixeco.framework.common.api.ApiDoc;

import com.zdy.im.user.vo.request.ImJoinFriendQueryRequestVo;
import com.zdy.im.user.vo.response.ImJoinFriendShowResponseVo;

/**
 * @Title: ImJoinFriendController.java
 * @Author 作者 : zdy
 * @CreateDate 创建时间: 2021-02-30
 * @version V1.0
 *  <pre>
 * 修改记录
 *    修改后版本:     修改人：  修改日期:     修改内容:
 * </pre>
 * @Description: TODO(说明) 对象缓存统一模板实现类;
 */
@ApiDoc(
        module = "用户加为好友申请信息记录表模块", isApp = true
)
@Controller
public class ImJoinFriendController {

    @Autowired
    private ImJoinFriendFacade imJoinFriendFacade;

    @Autowired
    private ImJoinFriendService imJoinFriendService;


    /**
    * @Title: 分页获取用户加为好友申请信息记录表信息
    * @Description:testRequestVo @{Link TestRequestVo}
    * @param
    * @return
    * @throw
    * @author suven
    * @date 2019-07-19 13:16:48
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    @ApiDoc(
            value = "分页获取用户加为好友申请信息记录表信息",
            request = ImJoinFriendQueryRequestVo.class,
            response = ImJoinFriendShowResponseVo.class
    )
    @RequestMapping(value = UrlCommand.USER_JOIN_FRIEND_LIST, method = RequestMethod.GET)
    public void list( OutputResponse out, ImJoinFriendQueryRequestVo joinFriendRequestVo){

        BasePage page =  BasePage.build().toPageSize(joinFriendRequestVo.getPageSize()).toPageNo(joinFriendRequestVo.getPageNo());
        page.toParamObject(joinFriendRequestVo.getUserId() );
        List<ImJoinFriendResponseDto> resultList = imJoinFriendService.getImJoinFriendByUserIdPage(page);
        if(null == resultList ){
           resultList = new ArrayList<>(0);
        }
        List<ImJoinFriendShowResponseVo> listVo = IterableConverter.convertList(resultList,ImJoinFriendShowResponseVo.class);
        ResponseResultList list =  ResponseResultList.build(listVo,page.getSize());
        out.write(list);
    }





    /**
    * @Title: 查看用户加为好友申请信息记录表信息
    * @Description:testRequestVo @{Link TestRequestVo}
    * @param
    * @return
    * @throw
    * @author suven
    * @date 2019-07-19 13:16:48
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    @ApiDoc(
            value = "查看用户加为好友申请信息记录表信息",
            request = HttpRequestByIdVo.class,
            response = ImJoinFriendShowResponseVo.class
    )
    @RequestMapping(value = UrlCommand.USER_JOIN_FRIEND_INFO ,method = RequestMethod.GET)
    public void detail(OutputResponse out, HttpRequestByIdVo idRequestVo){

            ImJoinFriendResponseDto imJoinFriendResponseDto = imJoinFriendService.getImJoinFriendById(idRequestVo.getId());
            ImJoinFriendShowResponseVo vo =  ImJoinFriendShowResponseVo.build().clone(imJoinFriendResponseDto);
        out.write(vo);
    }

    /**
     * @Title: 查看用户加为好友申请信息记录表信息
     * @Description:testRequestVo @{Link TestRequestVo}
     * @param
     * @return
     * @throw
     * @author suven
     * @date 2019-07-19 13:16:48
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    @ApiDoc(
            value = "拒绝加为好友",
            request = ImRefuseJoinFriendRequestVo.class,
            response = boolean.class
    )
    @RequestMapping(value = UrlCommand.USER_JOIN_FRIEND_REFUSE ,method = RequestMethod.GET)
    public void refuseJoinFriend(OutputResponse out, ImRefuseJoinFriendRequestVo idRequestVo){
        ImJoinFriendStatusRequestDto joinStatus = ImJoinFriendStatusRequestDto.build();
        joinStatus.toId(idRequestVo.getJoinFriendId());
        joinStatus.toJoinStatus(idRequestVo.getJoinStatus())
                .toSendUserId(idRequestVo.getSendUserId())
                .toToId(idRequestVo.getFriendId());

        boolean Status = imJoinFriendService.updateImJoinFriendStatus(joinStatus);
        out.write(Status);
    }

}
